//@author A0087191Y
package net.mysoc.w111j.service.actions;

import net.mysoc.w111j.model.Expense;
import net.mysoc.w111j.model.User;

/**
 * An {@code Action} to undo the adding of an {@code Expense}.
 */
public class AddExpenseAction implements Action {
    private final User user;
    private final int newExpenseId;
    private String status;

    public AddExpenseAction(User user, Expense newExpense) {
        this.user = user;
        this.newExpenseId = newExpense.getId();
        setStatus(newExpense);
    }

    @Override
    public void undo() {
        user.removeExpense(newExpenseId);
    }

    private void setStatus(Expense expense) {
        status = "New expense added: " + expense.getName() + ".";
    }

    @Override
    public String getStatus() {
        return status;
    }
}
